﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;

namespace BLL
{
    public class NoticeManager
    {
        private static EFHelper<OASystemEntities> _helper = new EFHelper<OASystemEntities>();

        /// <summary>
        /// 查询公告列表
        /// </summary>
        /// <returns></returns>
        public static List<OA_Notice> QueryList(int pageNum,int PageSize)
        {

            try
            {
                return _helper.PageQuery<OA_Notice>(null,n=>n.UpdateTime,pageNum,PageSize).ToList();
            }
            catch (Exception ex)
            {
                return new List<OA_Notice>();
            }
        }

        /// <summary>
        /// 获取公告列表集合
        /// </summary>
        /// <returns></returns>
        public static List<OA_Notice> QueryList()
        {

            try
            {
                return _helper.QueryList<OA_Notice>(null).ToList();
            }
            catch (Exception ex)
            {
                return new List<OA_Notice>();
            }
        }


        /// <summary>
        /// 发布公告
        /// </summary>
        /// <param name="notice"></param>
        /// <returns></returns>
        public bool Insert(OA_Notice notice)
        {
            try
            {
                notice.UserId = (System.Web.HttpContext.Current.Session["info"] as Model.OA_UserAccount).Id;
                notice.InsertTime = DateTime.Now;
                notice.UpdateTime = DateTime.Now;
                var num = _helper.Insert<OA_Notice>(notice);
                if (num == 1)
                    return true;
                else
                    return false;
            }
            catch (Exception)
            {
                
                throw;
            }

        }

    }
}
